package JPetStore.web.servlet;

import JPetStore.domain.Product;
import JPetStore.service.CatalogService;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class categoryShowServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String categoryId = req.getParameter("categoryId");
        CatalogService catalogService = new CatalogService();
        List<Product> productList = catalogService.getProductListByCategory(categoryId);

        String result = JSON.toJSONString(productList);
        System.out.println(result);

        resp.setContentType("text/json; charset=utf-8");
        PrintWriter out = resp.getWriter();
        out.print(result);
    }
}
